<?php
/**
 * @package LaravelBoot
 *
 * @internal
 *
 * @author mawenpei
 * @date 2019/3/13 13:48
 * @version
 */
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class MobileRechargeOrder extends Model
{
    protected $table = 'mobile_recharge_order';

    public $guarded = [];

    public $appends = ['status_name'];

    // 0待支付，1已支付，2待充值，3充值完成，-1取消
    const STATUS_INIT = 0;
    const STATUS_PAID = 1;
    const STATUS_PROCESSING = 2;
    const STATUS_DONE = 3;
    const STATUS_CANCELLED = -1;

    // 1套餐充值,2直接充值
    const TYPE_RECHARGE = 1;
    const TYPE_DIRECT = 2;

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function oilCard()
    {
        return $this->belongsTo(OilCard::class);
    }

    public function detail()
    {
        return $this->hasMany(RechargeOrderDetail::class);
    }

    public function recharge()
    {
        return $this->belongsTo(Recharge::class);
    }

    public function pay()
    {
        return $this->belongsTo(Pay::class);
    }
    
    public function getStatusNameAttribute()
    {
        // 0待支付，1已支付，2待充值，3充值完成，-1取消
        switch ($this->status) {
            case 1:
                return '已支付';
            case 2:
                return '进行中';
            case 3:
                return '充值完成';
            case -1:
                return '已取消';
            case 0:
                return '待支付';
            default:
                return '未定义';
        }
    }
}